<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1">
<input type="text" id="i2">
<input type="button" value="加" onclick="f1()">
<input type="button" value="减" onclick="f2()">
<input type="button" value="乘" onclick="f3()">
<input type="button" value="除" onclick="f4()">
<div>
    结果:<span></span>
</div>

<script>
    function f() {
        let d = document.querySelector("span");
        let i = document.querySelector("#i1")
        let i1 = document.querySelector("#i2")
        if (isNaN(i.value)){
            d.innerText = "输入错误!";
        }
    }

    function f1() {
        let d = document.querySelector("span");
        let i = document.querySelector("#i1")
        let i1 = document.querySelector("#i2")
        if (isNaN(i.value)){
            d.innerText = "输入错误!";
        }
        d.innerText = i.value*1 + i1.value*1;
    }
    function f2() {
        let d = document.querySelector("span");
        let i = document.querySelector("#i1")
        let i1 = document.querySelector("#i2")
        if (isNaN(i.value)){
            d.innerText = "输入错误!";
        }
        d.innerText = i.value - i1.value;
    }
    function f3() {
        let d = document.querySelector("span");
        let i = document.querySelector("#i1")
        let i1 = document.querySelector("#i2")
        if (isNaN(i.value)){
            d.innerText = "输入错误!";
        }
        d.innerText = i.value * i1.value;
    }
    function f4() {
        let d = document.querySelector("div");
        let i = document.querySelector("#i1")
        let i1 = document.querySelector("#i2")
        if (isNaN(i.value)){
            d.innerText = "输入错误!";
        }
        d.innerText = i.value / i1.value;
    }
</script>
</body>
</html>